<template>
	<view class="container">


		<form @submit="formSubmit">
			<view class="uni-form-item uni-column">
				<label for="">用户名：</label>
				<input class="uni-input" type="text" name="user_name" value="" placeholder="" />
			</view>
			<view class="uni-form-item uni-column">
				<label for="">密码：</label>
				<input class="uni-input" type="safe-password" name="password" value="" placeholder="" />
			</view>
			<view class="uni-btn-v">
				<button form-type="submit" class="btn-submit" type="primary" size="mini">登陆</button>
			</view>
		</form>

	</view>
</template>

<script>
	import {encrypt,decrypt} from '@/sm4.js';
	 import {getSign,verifySign} from '@/sign.js'; 
	export default {
		data(){
			return{
				
			}
		},
		mounted(){
			// let data="111"
			// let sign=getSign(data)
			// console.log(sign)
			
		},
		methods:{
		 async formSubmit(e){
				var form=e.detail.value
				var param={}
				param.user_name=form.user_name
				param.password=form.password
				const response=await this.$http.login(param)
				if(response.code==1){
					let token=encrypt(response.data.token)
					uni.setStorageSync("token",token)
					
					var response2=await this.$http.getUserInfo()
					if(response2.code==1){
						console.log('login',response2.data)
						uni.reLaunch({
							url: '/pages/index/index'
						});
						
						
					}
					
				}else{
					
					uni.showToast({
						title: "用户名或密码错误",
						icon: 'error',
						duration: 3000 // 持续时间，单位为毫秒
					})
				}
			}
				
		},
		created() {
		}
	};
</script>

<style scoped>
	.container {
		display: flex;
		justify-content: center;
		align-items: center;
		height: 100vh;
		background-color: #F6F6F6;
		/* border: 1px solid black; */
	}

	.uni-form-item {
		height: 40px;
		
	}


	.uni-form-item input,
	.uni-form-item label {
		display: inline-block;
		/* border: 1px solid black; */
	}
	.uni-form-item label{
		width: 70px;
		float: left;
		text-align: justify;
	}
	.uni-form-item input{
		border: 1px solid #D7D7D7
		
	}
	.uni-btn-v{
		text-align: center;
	}
</style>